//
// Created by wze-zero on 2024/9/18 018.
//
#include <iostream>

using namespace std;

char check(char ch[1000][1000], int i, int j) {
    int count = 0;
    if (ch[i][j] == '*') {
        return '*';
    } else {
        if (ch[i - 1][j - 1] == '*') count++;
        if (ch[i - 1][j] == '*') count++;
        if (ch[i - 1][j + 1] == '*') count++;
        if (ch[i][j - 1] == '*') count++;
        if (ch[i][j + 1] == '*') count++;
        if (ch[i + 1][j - 1] == '*') count++;
        if (ch[i + 1][j] == '*') count++;
        if (ch[i + 1][j + 1] == '*') count++;
        return '0' + count;
    }
}

int main() {
    int n, m;
    char arr[1000][1000];
    cin >> n >> m;
    for (int i = 0; i <= n + 1; ++i) {
        for (int j = 0; j <= m + 1; ++j) {
            arr[i][j] = '.';
        }
    }
    for (int i = 1; i < n + 1; ++i) {
        for (int j = 1; j < m + 1; ++j) {
            cin >> arr[i][j];
        }
    }
    for (int i = 1; i < n + 1; ++i) {
        for (int j = 1; j < m + 1; ++j) {
            cout << check(arr, i, j);
        }
        cout << endl;
    }
    return 0;
}